home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-20 | 2.9 KB | 92 lines | [TEXT/CWIE] |
-
- #include "EventHandlerTable.h"
-
- //========================================================================================
- // CLASS TEventHandlerTable
- //========================================================================================
-
- #include <Events.h>
-
- //----------------------------------------------------------------------------------------
- // TEventHandlerTable::TEventHandlerTable
- //----------------------------------------------------------------------------------------
- TEventHandlerTable::TEventHandlerTable()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TEventHandlerTable::~TEventHandlerTable
- //----------------------------------------------------------------------------------------
- TEventHandlerTable::~TEventHandlerTable()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TEventHandlerTable::InstallHandler
- //----------------------------------------------------------------------------------------
- OSStatus TEventHandlerTable::InstallHandler(AEEventClass handlerClass, AEEventID handlerID, EventHandlerProcPtr handler, UInt32 handlerRefcon)
- {
- OSStatus err = noErr;
-
- #if GENERATINGCFM
-
- //
- // In this case we should only call InstallHandler once per handler that
- // we wish to install, so we'll just go ahead and leak memory like crazy
- // (it's not really a memory leak, as we want eventHandlerRD to stick
- // around until the application quits, at which time it will be freed
- // up along with the rest of the application's resources.
- //
- AEEventHandlerUPP eventHandlerRD = NewRoutineDescriptor((ProcPtr) handler, uppAEEventHandlerProcInfo, GetCurrentISA());
- err = AEInstallEventHandler(handlerClass, handlerID, eventHandlerRD, handlerRefcon, false);
-
- #else
-
- //
- // In this case, an EventHandlerProcPtr should be the same as a AEEventHandlerUPP,
- // so we won't bother to typecast
- //
- err = AEInstallEventHandler(handlerClass, handlerID, handler, handlerRefcon, false);
-
- #endif
-
- return err;
- }
-
- //----------------------------------------------------------------------------------------
- // TEventHandlerTable::Receive
- //----------------------------------------------------------------------------------------
- OSStatus TEventHandlerTable::Receive(AEReceiveMode receiveMode, long maxSleepTime)
- {
- OSStatus err = noErr;
- Boolean receiving = true;
-
- while(receiving)
- {
- EventRecord event;
- WaitNextEvent(everyEvent, &event, maxSleepTime, nil);
-
- switch(event.what)
- {
- //
- // We live for high level events (and not much else)
- //
- case kHighLevelEvent:
- {
- //
- // We've installed the Futures package,
- // so any call to AEProcessAppleEvent
- // will spawn a thread to process the event
- //
- err = AEProcessAppleEvent(&event);
- if((receiveMode == kAEReceiveOneEvent) || ((receiveMode == kAEReceiveUntilUnhandledEvent) && (err == errAEEventNotHandled)))
- receiving = false;
- break;
- }
- }
- }
-
- return err;
- }
-
-